#include "stdafx.h"

#include <MyFC/CmdCheckBox.h>
#include <MyFC/Utility.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

namespace My {

CmdCheckBox::CmdCheckBox(UINT nID, LPCTSTR szGlyph, LPCTSTR szMask)
	: CheckBox(szGlyph, szMask), m_Command(nID), m_Enabled(true)
{

}			 

void CmdCheckBox::HandleClick()
{
	AfxGetMainWnd()->SendMessage(WM_COMMAND, m_Command, 0);
	HandleUpdateUI();
}	

void CmdCheckBox::HandleUpdateUI()
{
	CheckBoxCmdUI state(* this);

	state.m_nID = m_Command;

	CWnd * pTarget = GetWindow();
	if (!pTarget->IsFrameWnd())
		pTarget = pTarget->GetParentFrame();

	state.DoUpdate(static_cast<CFrameWnd *>(pTarget), TRUE);
}

void CmdCheckBox::SetEnabled(bool on)
{
	if (on != m_Enabled) {
		m_Enabled = on;
		Invalidate();
	}
}

void CmdCheckBox::SetState(State s)
{
	if (s != m_State) {
		m_State = s;
		Invalidate();
	}
}

// CheckBoxCmdUI

void CheckBoxCmdUI::Enable(BOOL bOn)
{	 
	m_Owner.SetEnabled(bOn != 0);
	m_bEnableChanged = true;
}

void CheckBoxCmdUI::SetCheck(int nCheck)
{
	CheckBox::State states[] = {
		CheckBox::Unchecked,
		CheckBox::Checked,
		CheckBox::Indeterminate
	};
	m_Owner.SetState(states[nCheck]);
}

void CheckBoxCmdUI::SetRadio(BOOL bOn)
{
	m_Owner.SetState(bOn ? CheckBox::Checked : CheckBox::Unchecked);
}

void CheckBoxCmdUI::SetText(LPCTSTR lpszText)
{
}




} // My

